/*
 * Singularity Engine
 * Copyright (C) 2010 Vyacheslav Vorobyov, All rights reserved.
 * See LICENSE for full license information.
 */

package org.singularity.io;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;


/**
 * @author vjache
 *
 */
public class InputCollection<VT> implements Input<VT> {

	private final Collection<DME<VT>> _coll;

	/**
	 * 
	 */
	public InputCollection(DME.Code aDmeCode, Collection<VT> aColl) {
		_coll = new ArrayList<DME<VT>>();
		for(VT item:aColl)
			_coll.add(new DMEImpl<VT>(aDmeCode, item));
	}
	/**
	 * 
	 */
	public InputCollection(DME.Code aDmeCode, VT... aItems) {
		_coll = new ArrayList<DME<VT>>();
		for(VT item:aItems)
			_coll.add(new DMEImpl<VT>(aDmeCode, item));
	}
	/**
	 * 
	 */
	public InputCollection(Collection<DME<VT>> aItems) {
		_coll = aItems;
	}
	/**
	 * 
	 */
	public InputCollection(DME<VT>... aItems) {
		_coll = new ArrayList<DME<VT>>();
		for(DME<VT> item:aItems)
			_coll.add(item);
	}
	
	public void add(DME<VT> aItem)
	{
		_coll.add(aItem);
	}

	/* (non-Javadoc)
	 * @see org.singularity.io.Input#iterator()
	 */
	@Override
	public CloseableIterator<DME<VT>> iterator() {
		return new CloseableIterator<DME<VT>>() {
			private final Iterator<DME<VT>> _it = _coll.iterator();
			@Override
			public void close() throws IOException {}
			@Override
			public boolean hasNext() {return _it.hasNext();}
			@Override
			public DME<VT> next() {return _it.next();}
			@Override
			public void remove() {_it.remove();}
		};
	}

}
